<!DOCTYPE html>
<html lang="zh-CN">

<head>
  <meta charset="utf-8">
  <title>Users &laquo; Admin</title>
  <link rel="stylesheet" href="../assets/vendors/bootstrap/css/bootstrap.css">
  <link rel="stylesheet" href="../assets/vendors/font-awesome/css/font-awesome.css">
  <link rel="stylesheet" href="../assets/vendors/nprogress/nprogress.css">
  <link rel="stylesheet" href="../assets/css/admin.css">
  <script src="../assets/vendors/nprogress/nprogress.js"></script>
  <script src="/login/status"></script>
  <script>
    if (!isLogin) location.href = 'login.html';
  </script>
</head>

<body>
  <script>
    NProgress.start()
  </script>

  <div class="main">
    <nav class="navbar">
      <button class="btn btn-default navbar-btn fa fa-bars"></button>
      <ul class="nav navbar-nav navbar-right">
        <li><a href="profile.html"><i class="fa fa-user"></i>个人中心</a></li>
        <li><a href="javascript:;" id="logout"><i class="fa fa-sign-out"></i>退出</a></li>
      </ul>
    </nav>
    <div class="container-fluid">
      <div class="page-title">
        <h1>用户</h1>
      </div>
      <!-- 有错误信息时展示 -->
      <div class="alert alert-danger" id="err" style="display:none">
        <strong>错误！</strong><span id="error"></span>
      </div>
      <div class="row">
        <div class="col-md-4" id="userbox">
        </div>
        <div class="col-md-8">
          <div class="page-action">
            <!-- show when multiple checked -->
            <a class="btn btn-danger btn-sm" href="javascript:;" id="dels" disabled>批量删除</a>
          </div>
          <table class="table table-striped table-bordered table-hover">
            <thead>
              <tr>
                <th class="text-center" width="40"><input type="checkbox" id="chescks"></th>
                <th class="text-center" width="80">头像</th>
                <th>邮箱</th>
                <th>昵称</th>
                <th>状态</th>
                <th>角色</th>
                <th class="text-center" width="100">操作</th>
              </tr>
            </thead>
            <tbody id="userlist">

            </tbody>
          </table>
        </div>
      </div>
    </div>
  </div>

  <div class="aside">
    <div class="profile">
      <img class="avatar" src="../uploads/avatar.jpg">
      <h3 class="name">Coder</h3>
    </div>
    <ul class="nav">
      <li>
        <a href="index.html"><i class="fa fa-dashboard"></i>仪表盘</a>
      </li>
      <li>
        <a href="#menu-posts" class="collapsed" data-toggle="collapse">
          <i class="fa fa-thumb-tack"></i>文章<i class="fa fa-angle-right"></i>
        </a>
        <ul id="menu-posts" class="collapse">
          <li><a href="posts.html">所有文章</a></li>
          <li><a href="post-add.html">写文章</a></li>
          <li><a href="categories.html">分类目录</a></li>
        </ul>
      </li>
      <li>
        <a href="comments.html"><i class="fa fa-comments"></i>评论</a>
      </li>
      <li class="active">
        <a href="users.html"><i class="fa fa-users"></i>用户</a>
      </li>
      <li>
        <a href="#menu-settings" class="collapsed" data-toggle="collapse">
          <i class="fa fa-cogs"></i>设置<i class="fa fa-angle-right"></i>
        </a>
        <ul id="menu-settings" class="collapse">
          <li><a href="slides.html">图片轮播</a></li>
          <li><a href="settings.html">网站设置</a></li>
        </ul>
      </li>
    </ul>
  </div>

  <script src="../assets/vendors/jquery/jquery.js"></script>
  <script src="../assets/vendors/bootstrap/js/bootstrap.js"></script>
  <script>
    NProgress.done()
  </script>
</body>
<script src="/assets/vendors/art-template/template-web.js"></script>
<script src='/assets/vendors/axios.min.js'></script>
<script src="/assets/js/common.js"></script>
<script src="../assets/js/usercom.js"></script>
<script type="text/html" id="userlistTpl">
  {{ each data v }}
  <tr>
    <td class="text-center"><input type="checkbox" data-id="{{ v._id }}"></td>
    <!-- <td class="text-center"><img class="avatar" src="{{ v.avatar ? v.avatar : '/assets/img/default.png' }}"></td> -->
    <td class="text-center"><img class="avatar" src="{{ v.avatar || '/assets/img/default.png' }}"></td>
    <td>{{ v.email }}</td>
    <td>{{ v.nickName }}</td>
    <td>{{ ['未激活', '已激活'][v.status] }}</td>
    <td>{{ { 'normal': '普通用户', 'admin': '超级管理员' }[v.role] }}</td>
    <td class="text-center">
      <a href="javascript:;" class="btn btn-default btn-xs edit" data-id="{{ v._id }}">编辑</a>
      <a href="javascript:;" class="btn btn-danger btn-xs del" data-id="{{ v._id }}">删除</a>
    </td>
  </tr>
  {{ /each }}
</script>

<script type="text/html" id="useraddTpl">
  <form id="addusers">
    <h2>添加新用户</h2>
    <div class="form-group">
      <label>头像</label>
      <div class="form-group">
        <label class="form-image">
          <input id="avatar" type="file">
          <img src="../assets/img/default.png" id="preview">
          <i class="mask fa fa-upload"></i>
        </label>
        <input type="hidden" name="avatar" id="hiddenAvatar">
      </div>
    </div>
    <div class="form-group">
      <label>邮箱</label>
      <input class="form-control" id="email" type="email" placeholder="请输入邮箱" name="email">
    </div>
    <div class="form-group">
      <label>昵称</label>
      <input class="form-control" id="username" type="text" placeholder="请输入昵称" name="nickName">
    </div>
    <div class="form-group">
      <label>密码</label>
      <input class="form-control" id="password" type="text" placeholder="请输入密码" name="password">
    </div>
    <div class="form-group">
      <div class="radio-inline">
        <label><input type="radio" name="status" value="0">未激活</label>
      </div>
      <div class="radio-inline">
        <label><input type="radio" name="status" value="1" checked>激活</label>
      </div>
    </div>
    <div class="form-group">
      <div class="radio-inline">
        <label><input type="radio" name="role" value="admin" checked>超级管理员</label>
      </div>
      <div class="radio-inline">
        <label><input type="radio" name="role" value="normal">普通用户</label>
      </div>
    </div>
    <div class="form-group">
      <button class="btn btn-primary" type="submit">添加</button>
    </div>
  </form>
</script>

<script type="text/html" id="usereditTpl">
  <!-- 用户编辑显示 -->
<form id="edtusers">
  <h2>编辑用户</h2>
  <div class="form-group">
    <label>头像</label>
    <div class="form-group">
      <label class="form-image">
        <input id="avatar" type="file">
        <img id="preview" src="{{ avatar || '/assets/img/default.png' }}">
        <i class="mask fa fa-upload"></i>
      </label>
      <input id="hiddenAvatar" type="hidden" name="avatar" value="{{ avatar || '' }}">
    </div>
  </div>
  <div class="form-group">
    <label>邮箱</label>
    <input class="form-control" disabled id="email" type="email" placeholder="请输入邮箱" name="email" value="{{ email }}">
  </div>
  <div class="form-group">
    <label>昵称</label>
    <input class="form-control" id="username" type="text" placeholder="请输入昵称" name="nickName" value="{{ nickName }}">
  </div>
  <div class="form-group">
    <label>密码</label>
    <input class="form-control" id="password" type="text" placeholder="请输入密码" name="password" value="{{ password }}">
  </div>
  <div class="form-group">
    <div class="radio-inline">
      <label><input type="radio" name="status" value="0" {{ status === 0 ? 'checked' : '' }}>未激活</label>
    </div>
    <div class="radio-inline">
      <label><input type="radio" name="status" value="1" checked {{ status === 0 ? 'checked' : '' }}>激活</label>
    </div>
  </div>
  <div class="form-group">
    <div class="radio-inline">
      <label><input type="radio" name="role" value="admin" checked>超级管理员</label>
    </div>
    <div class="radio-inline">
      <label><input type="radio" name="role" value="normal">普通用户</label>
    </div>
  </div>
  <div class="form-group">
    <input type="submit" class="btn btn-primary" id="editbtn" value="提交" data-id="{{ _id }}">
    <input type="button" class="btn btn-danger" value="取消" onclick="location.reload()">
  </div>
</form>
</script>
</html>